#include int servoPin1 = 8; //Connects the yellow wire to pin 3 int LED1= 3; int servoPin2 =7 ; //Connects the yellow wire to pin 3 int LED2= 2; int myAngle; //This sets the variable for your servo angle int pulseWidth; // servoPulse function variable #define TX 0 #define RX 1 #define lightTrigger 1 SoftwareSerial data (RX,TX); void servoPulse(int servoPin, int myAngle) { pulseWidth = (myAngle * 10) + 600; //This Procedure translates myAngle to the correct delay in order to make digitalWrite(servoPin1, HIGH); //the servo move to the correct set angle. digitalWrite(servoPin2, HIGH); digitalWrite(LED1, HIGH); digitalWrite(LED2, HIGH); delayMicroseconds(pulseWidth); digitalWrite(servoPin1, LOW); digitalWrite(servoPin2, LOW); } void setup () { pinMode(LED1, OUTPUT); pinMode(servoPin1, OUTPUT); //sets pin 3 as output pinMode(LED2, OUTPUT); pinMode(servoPin2, OUTPUT); data.begin(9600); } void loop() { String sensorValue; if (data.available()){ for (myAngle=0; myAngle<=90; myAngle= myAngle+5) //The angle starts at 50 degrees and increases by increments //of one until it reaches 120 { servoPulse(servoPin1, myAngle); //Calls the servoPulse Procedure and sets pin and angle delay(20); //refreshes cycle } for (myAngle=90; myAngle>=0; myAngle= myAngle-5) //The angle starts at 120 degrees and decreases by increments //of one until it reaches 50 { servoPulse(servoPin1, myAngle); //sets pin and angle delay(20); //refreshes cycle } for (myAngle=0; myAngle<=180; myAngle= myAngle+5) //The angle starts at 50 degrees and increases by increments //of one until it reaches 120 { servoPulse(servoPin1, myAngle); //Calls the servoPulse Procedure and sets pin and angle delay(20); //refreshes cycle } for (myAngle=180; myAngle>=0; myAngle= myAngle-5) //The angle starts at 120 degrees and decreases by increments //of one until it reaches 50 { servoPulse(servoPin1, myAngle); //sets pin and angle delay(20); //refreshes cycle } //second servo for (myAngle=0; myAngle<=180; myAngle= myAngle+10) //The angle starts at 50 degrees and increases by increments //of one until it reaches 120 { servoPulse(servoPin2, myAngle); //Calls the servoPulse Procedure and sets pin and angle delay(20); //refreshes cycle } for (myAngle=180; myAngle>=0; myAngle= myAngle-10) //The angle starts at 120 degrees and decreases by increments //of one until it reaches 50 { servoPulse(servoPin2, myAngle); //sets pin and angle delay(20); //refreshes cycle } for (myAngle=0; myAngle<=180; myAngle= myAngle+5) //The angle starts at 50 degrees and increases by increments //of one until it reaches 120 { servoPulse(servoPin2, myAngle); //Calls the servoPulse Procedure and sets pin and angle delay(20); //refreshes cycle } for (myAngle=180; myAngle>=0; myAngle= myAngle-5) //The angle starts at 120 degrees and decreases by increments //of one until it reaches 50 { servoPulse(servoPin2, myAngle); //sets pin and angle delay(20); //refreshes cycle } } }